<?php

/**
 * This is the model class for table "port_tb_users".
 *
 * The followings are the available columns in table 'port_tb_users':
 * @property integer $user_id
 * @property integer $user_func_id
 * @property integer $user_perf_id
 * @property string $user_login
 * @property string $user_senha
 * @property string $user_dtcadastro
 * @property string $user_mudarsenha
 * @property string $user_conterrosenha
 * @property string $user_ativo
 *
 * The followings are the available model relations:
 * @property PortTbReserva[] $portTbReservas
 * @property PortTbPartesInteressadas[] $portTbPartesInteressadases
 * @property PortTbOficio[] $portTbOficios
 * @property PortTbNoticias[] $portTbNoticiases
 * @property PortTbAtaReuniao[] $portTbAtaReuniaos
 * @property PortTbFuncionario $userFunc
 * @property PortTbPerfis $userPerf
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'port_tb_users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_func_id, user_perf_id, user_login, user_senha, user_dtcadastro', 'required'),
			array('user_func_id, user_perf_id', 'numerical', 'integerOnly'=>true),
			array('user_login', 'length', 'max'=>45),
			array('user_senha', 'length', 'max'=>32),
			array('user_mudarsenha, user_conterrosenha, user_ativo', 'length', 'max'=>1),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, user_func_id, user_perf_id, user_login, user_senha, user_dtcadastro, user_mudarsenha, user_conterrosenha, user_ativo', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'portTbReservas' => array(self::HAS_MANY, 'PortTbReserva', 'rese_user_id'),
			'portTbPartesInteressadases' => array(self::HAS_MANY, 'PortTbPartesInteressadas', 'port_tb_users_user_id'),
			'portTbOficios' => array(self::HAS_MANY, 'PortTbOficio', 'ofic_user_id'),
			'portTbNoticiases' => array(self::HAS_MANY, 'PortTbNoticias', 'noti_user_id'),
			'portTbAtaReuniaos' => array(self::HAS_MANY, 'PortTbAtaReuniao', 'atre_user_id'),
			'userFunc' => array(self::BELONGS_TO, 'PortTbFuncionario', 'user_func_id'),
			'userPerf' => array(self::BELONGS_TO, 'PortTbPerfis', 'user_perf_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'user_func_id' => 'User Func',
			'user_perf_id' => 'User Perf',
			'user_login' => 'User Login',
			'user_senha' => 'User Senha',
			'user_dtcadastro' => 'User Dtcadastro',
			'user_mudarsenha' => 'User Mudarsenha',
			'user_conterrosenha' => 'User Conterrosenha',
			'user_ativo' => 'User Ativo',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('user_func_id',$this->user_func_id);
		$criteria->compare('user_perf_id',$this->user_perf_id);
		$criteria->compare('user_login',$this->user_login,true);
		$criteria->compare('user_senha',$this->user_senha,true);
		$criteria->compare('user_dtcadastro',$this->user_dtcadastro,true);
		$criteria->compare('user_mudarsenha',$this->user_mudarsenha,true);
		$criteria->compare('user_conterrosenha',$this->user_conterrosenha,true);
		$criteria->compare('user_ativo',$this->user_ativo,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}